# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

import copy

class Solution:
    # @param {TreeNode} root
    # @return {string[]}
    def binaryTreePaths(self, root):
        ret = []
        acc = []
        def find(root):
            acc.append(root.val)
            if root.left or root.right:
                if root.left: find(root.left)
                if root.right: find(root.right)
            else:
                ret.append(copy.copy(acc))
            acc.pop()
        if root: find(root)
        return ['->'.join(map(str, r)) for r in ret]